/*
 * CorePassController.h
 *
 *  Created on: Dec 12, 2014
 *      Authors: Avihay Avitan & Stefan Farcas
 */

#ifndef COREPASSCONTROLLER_H_
#define COREPASSCONTROLLER_H_
#include "../CoreController/RequiredIncludes.h"
#include <boost/thread.hpp>

namespace CoreSpace {

/**
 * CorePassController class provides the operations for performing the critical section of communicating with a satellite
 */
class CorePassController {
public:
	CorePassController(ICommunicationModuleBridge * connection, PassVector * pass, 	SatelliteTracker * tracker);
	virtual ~CorePassController();

	bool init(boost::thread * mainThread, boost::thread * trackerThread);
	void run();
	void trackSatellite();

private:
	bool transmitINITcommand()throw (boost::thread_interrupted&);
	bool transmitGOCMD() throw (boost::thread_interrupted&);
	bool sendCommandsToSat()throw (boost::thread_interrupted&);
	bool sendENDCommand()throw (boost::thread_interrupted&);
	void checkMainWatchDog() throw (boost::thread_interrupted&);
	void reportStatus();
	void logPassCoreControllerInfo(string function, string content);

	int status;
	long startTime;
	ICommunicationModuleBridge * connection;
	PassVector * pass;
	SatelliteTracker * tracker;
	PassLogger * logger;
	boost::thread * mainThread;
	boost::thread * trackerThread;
	volatile bool isOneInterruptedAlready;

public:
	volatile bool * interruptedFlag;
};

} /* namespace CoreSpace */

#endif /* COREPASSCONTROLLER_H_ */
